package com.codeyang.mocktest2.mockit;

import com.codeyang.mocktest2.mapper.TUserMapper;
import com.codeyang.mocktest2.service.TUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 18-2
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class MockBean02 {

    /**
     * @MockBean 是代理对象的话，还是无法解决调用真实的方法
     */
    @MockBean
    private TUserMapper userMapper;

    @MockBean
    private TUserService tUserService;


    @Test
    public void tUserMapperQueryAll() throws Exception {
        Mockito.when(userMapper.selectAll()).thenCallRealMethod();
        System.out.println(userMapper.selectAll());
    }
    @Test
    public void tUserServiceQueryAll() throws Exception {
        Mockito.when(tUserService.queryAll()).thenCallRealMethod();
        System.out.println(tUserService.queryAll());
    }
}